import * as http from '@/api/todos'

export default {
  namespaced: true,
  state: {
    count: 100,
    todos: []
  },
  mutations: {
    // 参数1 state
    // 参数2 payload 组件传递过来的参数
    ADD_COUNT(state, { step = 1 }) {
      state.count += step
    },
    SET_TODOS(state, payload) {
      state.todos = payload
    }
  },
  actions: {
    // 参数1 object
    //    commit、getters、state、dispatch、rootGetters、rootState
    getTodos({ commit, state }, payload) {
      // console.log(content, payload)
      http.getTodos().then((res) => {
        commit('SET_TODOS', res)
      })
    }
  },
  getters: {
    getCount(state) {
      return state.count + '~~~~~~'
    }
  }
}
